home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7809 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: news.eunet.cz!usenet
  2. From: Borivoj Kostka <kostka@tovek.cz>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How big is the 0
  5. Date: 19 Feb 1996 09:54:52 GMT
  6. Organization: EUnet Czechia (a customer)
  7. Message-ID: <4g9hdc$cjj@news.eunet.cz>
  8. NNTP-Posting-Host: sherlock.dial-up.cz
  9.  
  10. anh@kuhub.cc.ukans.edu writes:
  11. > Hello,
  12. > In C, anytime I need to do a null pointer check I would do this:
  13. >     MyType *p;
  14. >     if(p==(MyType*)0)
  15. >         bla;
  16. > The new operator supposedly return a 0 upon failure. Can I rely on the 
  17. > compiler to make sure the 0 is as big as the size of the pointer? For 
  18. > example, ALPHA's pointers are 64 bits long which is different from the 32 bits
  19. > int.
  20. > Thank-you.
  21. > Anh
  22. The new operator NEVER returns a 0. It throws an exception. You have to 
  23. catch this exception. For example (in BC 4.5)
  24.  
  25. try {
  26.   buf = new char[DYNA_BIG_BUF];
  27.   }
  28. catch (xalloc) {
  29.   MessageBox("Not enough memory", "Exception Error", MB_ICONEXCLAMATION|MB_OK);
  30.   ...
  31.   }
  32.  
  33. In BC there is some way, how to make new operator to return
  34. NULL upon failure. Check documentation.
  35.  
  36.